// 定义XsysRoleGrid类的构造函数
var XsysRoleGrid = function (cfg) {

    // 为了在任何情况下可以获得XsysRoleGrid的实例对象
    var me = this;

    // 调用父类构造函数
    XsysRoleGrid.superclass.constructor.call(this, Ext.apply({
        url: 'xsys/role/list',
        woIdProperty: 'id',
        woNameProperty: 'name',
        woTitle: '角色列表',
        singleSelect: false,
        woPaging : true,
        woColumns: [
                        {
            header: 'ID',
            dataIndex: 'id',
            hidden: true,
            width: 150
        }
                        ,{
            header: '名称',
            dataIndex: 'name',
            hidden: false,
            width: 150
        }
                ,{
            header: '描述',
            dataIndex: 'description',
            hidden: false,
            width: 150
        }
                                , {
            header: '菜单ID',
            dataIndex: 'menusId',
            hidden: true,
            width: 150
        }, {
            header: '菜单',
            dataIndex: 'menusName',
            hidden: false,
            width: 150
        }
                ],
        woButtons: [{
            woButtonType: 'wo.list.create', // 创建按钮
            woForm: XsysRoleCreateForm, // 创建表单类
            woGridSelectType: 'singleornone' // 设置列表选择类型：单选或者不选
        }, {
            woButtonType: 'wo.list.delete', // 删除按钮
            woGridSelectType: 'single', // 设置列表选择类型：单选
            woUrl: 'xsys/role/delete' // 设置删除提交url，key值为selectedIds
        }],
        // 查询字段
        woSearchFields: [{
            items: [{
                name: 'searchContent',
                fieldLabel: '查询内容',
                width: 100
            }]
        }],
        woUpdateForm: XsysRoleUpdateForm // 设置列表双击时，弹出的修改表单类
    }, cfg));
};
// XsysRoleGrid继承Wo.GridPanel
Ext.extend(XsysRoleGrid, Wo.GridPanel, {});

Wo.loadJsByClass('XsysMenuGrid');

// 定义角色的创建表单，继承Wo.FormPanel
var XsysRoleCreateForm = function (cfg) {
    // 调用父类构造函数
    XsysRoleCreateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/role/create',
        title: '创建角色',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                                allowBlank: true,
                width: 200
            }]
        }
                        , {
            items: [{
                name: 'name',
                fieldLabel: '名称',
                allowBlank: true,
                                width: 200
            }]
        }
                , {
            items: [{
                name: 'description',
                fieldLabel: '描述',
                allowBlank: true,
                                width: 200
            }]
        }
                                , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: 'menusId', // 菜单id
                name: 'menusName', // 菜单名称
                fieldLabel: '菜单',
                selectLength : -1, // 设置多选
                woPanelClass: 'XsysMenuGrid', // 弹出grid的类
                width: 200
            }]
        }
                ]
    }, cfg));
};
// 继承
Ext.extend(XsysRoleCreateForm, Wo.FormPanel, {});

// 定义角色修改表单
var XsysRoleUpdateForm = function (cfg) {
    XsysRoleUpdateForm.superclass.constructor.call(this, Ext.apply({
        columns: 1,
        url: 'xsys/role/update',
        title: '修改角色',
        width: 400,
        height: 300,
        items: [
    	                {
            items: [{
                name: 'id',
                fieldLabel: 'ID',
                width: 200,
                readOnly: true,
                value: cfg.row.get('id')
            }]
        }
    	    	        , {
            items: [{
                name: 'name',
                fieldLabel: '名称',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('name')
            }]
        }
    	        , {
            items: [{
                name: 'description',
                fieldLabel: '描述',
                width: 200,
                                allowBlank: true,
                value: cfg.row.get('description')
            }]
        }
    	    	    	        , {
            items: [{
                xtype: 'objectsearch', // 控件类型设置为对象查找
                hiddenName: 'menusId', // 菜单id
                name: 'menusName', // 菜单名称
                fieldLabel: '菜单',
                value: cfg.row.get('menusId'),
                woText: cfg.row.get('menusName'),
                selectLength : -1, // 设置多选
                woPanelClass: 'XsysMenuGrid', // 弹出grid的类
                width: 200
            }]
        }
            	]
    }, cfg));
};
Ext.extend(XsysRoleUpdateForm, Wo.FormPanel, {});